const babel = require('@babel/core');
const path = require('path');
const loaderUtils = require('loader-utils');
function loader(inputSource){
    let options =loaderUtils.getOptions(this);
    options = {
        ...options,
        sourceMaps:true,//告诉 babel我要生成sourcemap
        filename:path.basename(this.resourcePath)
    }
    let {code,map,ast} = babel.transform(inputSource,options);
    //我们可以把sourcemap ast 都传给webpack.这样webpack就不再需要自己把源代码转语法树了，也不需要自己生成sourcemap
    return this.callback(null,code,map);
}
module.exports = loader;